import {
  throttle2,
} from "../../../../utils/util";
Component({
  options: {
    addGlobalClass: true,
    pureDataPattern: /^_/, // 指定所有 _ 开头的数据字段为纯数据字段
  },
  /**
   * 组件的属性列表
   */
  properties: {
    cityList: {
      type: Array,
      value: [[], []]
    },
    index: {
      type: Number,
      value: 0
    },
    categoryList: {
      type: Array,
      value: []
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    cityResult: '',
    categoryIndex: -1,
    pulldown: '../../../../assets/image/customerIntelligent/pulldown.svg',
    pulldownSelect: '../../../../assets/image/customerIntelligent/pulldown_selected.svg',
    chooseDefault: '../../../../assets/image/customerIntelligent/choose_default.svg',
    chooseSelected: '../../../../assets/image/customerIntelligent/choose_selected.svg',
    result: {
      vaccineCategoryId: '',
      vaccineCategoryName: '',
      areaId: '',
      areaName: '',
      vaccineUrgencyStatus: 0, // 0 默认  1 着急  2 不着急
    }
  },
  /**
   * 组件的方法列表
   */
  methods: {
    changeCategory(e) {
      const { value } = e.detail || {}
      this.setData({
        categoryIndex: value,
        'result.vaccineCategoryId': this.data.categoryList[value].id,
        'result.vaccineCategoryName': this.data.categoryList[value].name,
      })
    },
    cancelCategory(e) {
      console.log('cancelCategory: ');
    },
    columnCity(e) {
      const { column, value } = e.detail;
      const { cityList } = this.data || {};
      // 第一列变动才需要
      column === 0 && this.triggerEvent('handleCity', {id: cityList[0][value].id, index: this.data.index})
    },
    changeCity(e) {
      const { value } = e.detail;
      const { cityList } = this.data;
      const cityResult = cityList[1][value[1] || 0].name
      this.setData({
        cityResult,
        'result.areaId': cityList[1][value[1] || 0].id,
        'result.areaName': cityList[1][value[1] || 0].name,
      })
    },
    cancelcity() {
      console.log('cancelcity: ');
    },
    onSave(e) {
      const { status } = e.currentTarget.dataset
      this.setData({
        'result.vaccineUrgencyStatus': +status,
      })
    },
    onSubmitBythrottle2: throttle2(function () {
      const result = this.data.result || {};
      if (!result.areaId) {
        wx.showToast({
          title: '请选择接种省/市',
          icon: 'none'
        })
        return
      }
      if (!result.vaccineCategoryId) {
        wx.showToast({
          title: '请选择接种品类',
          icon: 'none'
        })
        return
      }
      this.triggerEvent("onSubmit", this.data.result);
    }, 2000),
    // 点击帮我推进推荐
    onSubmit() {
      this.onSubmitBythrottle2()
    }
  }
})